import { InitComponent } from './../init/init.component';
import { NavController } from 'ionic-angular';
import { ConfirmParams } from './../../component/primeng/confirm/confirm.module';
import { OnlineManager } from './../../common/onlineManager';
import { MdDialog } from "@angular/material";
import { SystemService } from './../../service/system.service';
import { Component } from '@angular/core';
import { NavigateService } from "../../service/index";
import { SyncDataService } from "../../service/index";
import { MessageBoxService, MessageResult, GrowlMessageType } from "../../component/index";

declare let EventRegistHandle: any;
@Component({
    //moduleId: module.id,
    selector: 'div[reset]',
    templateUrl: './reset.component.html',
    styleUrls: ['./reset.component.scss']
})
export class ResetComponent {
    constructor(
        private router: NavigateService,
        private syncSvr: SyncDataService,
        private msgSvr: MessageBoxService,
        private sysSvr: SystemService,
        private dialog: MdDialog,
        public navCtrl: NavController
    ) { }
    async reset() {
        let confirmParams: ConfirmParams = {
            title: "重新设置终端",
            content: "重置终端将会清理当前终端缓存的所有数据，然后重新设置终端，确认要重置？"
        }
        let isReset = await MessageBoxService.Current.Show(this.dialog, confirmParams);
        if (isReset == MessageResult.Ok) {
            await this.syncSvr.ClearAll();
            this.sysSvr.unboundTerminial()
            localStorage.clear();
            // EventRegistHandle.Call("ClearOnlineTimer");
            OnlineManager.Current.stopTimer();
            // this.router.navigate(["init"]);
            this.navCtrl.setRoot(InitComponent);
        }
    }
    ionViewWillEnter() {
        this.router.registGoBack(() => {
            let backBtn = document.getElementById("reset-back-btn");
            if (backBtn) {
                backBtn.click();
            }
        });
    }
    goBack() {
        // return this.router.navigate(["setup"]);
        this.navCtrl.pop({ animate: false });
    }
}